<template>
  <el-main>
    <el-row>
      <el-col>
        <div class="grid-content bg-purple-light">
          <div class="grid-content bg-purple">
            <i class="el-icon-s-promotion"> </i> 租房分期
            <hr>
            <div class="about">
              <el-table
                :data="tableData">
                <el-table-column
                  prop="jrProductName"
                  label="产品名称">
                </el-table-column>
                <el-table-column
                  prop="companyName"
                  label="资方">
                </el-table-column>
                <el-table-column
                  prop="bankName"
                  label="银行名称"
                >
                </el-table-column>
                <el-table-column
                  prop="bankCardNumber"
                  label="账户信息"
                >
                </el-table-column>
                <el-table-column
                  prop="repaymentType"
                  label="还款方式"
                >
                  <template scope="scope">
                    <div v-if="scope.row.repaymentType==1">按月还款</div>
                    <div v-if="scope.row.repaymentType==2">按季还款</div>
                    <div v-if="scope.row.repaymentType==3">按租约周期支付</div>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="creditLine"
                  label="授信额度"
                >
                </el-table-column>
                <el-table-column
                  prop="delFlg"
                  label="状态"
                >
                  <template scope="scope">
                    <div v-if="scope.row.delFlg==0" style="color: green">正常</div>
                    <div v-if="scope.row.delFlg==1" style="color: red">已作废</div>
                  </template>
                </el-table-column>
                <el-table-column
                  fixed="right"
                  label="操作"
                  width="200">
                  <template scope="scope">
                    <div v-if="scope.row.delFlg==0">
                      <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                      <el-button
                        type="text"
                        size="small"
                        @click="handleEdit(scope.row)">编辑
                      </el-button>
                      <el-button
                        size="small"
                        type="text"

                        @click="handleDelFlg(scope.row)">作废
                      </el-button>
                    </div>
                    <div v-if="scope.row.delFlg==1">
                      <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                      <el-button
                        type="text"
                        size="small"
                        @click="handleEdit(scope.row)" disabled>编辑
                      </el-button>
                      <el-button
                        size="small"
                        type="text"
                        @click="handleDelete(scope.row)">删除
                      </el-button>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <br>
    <br>
    <br>
    <el-row>
      <el-col>
        <div class="grid-content bg-purple">
          <i class="el-icon-s-promotion"> </i> 收房贷
          <hr>
          <div class="about">
            <el-table
              :data="tableData1">
              <el-table-column
                prop="jrProductName"
                label="产品名称"
              >
              </el-table-column>
              <el-table-column
                prop="companyName"
                label="资方"
              >
              </el-table-column>
              <el-table-column
                prop="bankName"
                label="银行名称"
              >
              </el-table-column>
              <el-table-column
                prop="bankCardNumber"
                label="账户信息"
              >
              </el-table-column>
              <el-table-column
                prop="repaymentType"
                label="还款方式"
              >
                <template scope="scope">
                  <div v-if="scope.row.repaymentType==1">按月还款</div>
                  <div v-if="scope.row.repaymentType==2">按季还款</div>
                  <div v-if="scope.row.repaymentType==3">按租约周期支付</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="creditLine"
                label="授信额度"
              >
              </el-table-column>
              <el-table-column
                prop="delFlg"
                label="状态"
              >
                <template scope="scope">
                  <div v-if="scope.row.delFlg==0" style="color: green">正常</div>
                  <div v-if="scope.row.delFlg==1" style="color: red">已作废</div>
                </template>
              </el-table-column>
              <el-table-column
                fixed="right"
                label="操作"
                width="200">
                <template scope="scope">
                  <div v-if="scope.row.delFlg==0">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button
                      type="text"
                      size="small"
                      @click="handleEdit(scope.row)">编辑
                    </el-button>
                    <el-button
                      size="small"
                      type="text"

                      @click="handleDelFlg(scope.row)">作废
                    </el-button>
                  </div>
                  <div v-if="scope.row.delFlg==1">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button
                      type="text"
                      size="small"
                      @click="handleEdit(scope.row)" disabled>编辑
                    </el-button>
                    <el-button
                      size="small"
                      type="text"
                      @click="handleDelete(scope.row)">删除
                    </el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </el-col>
    </el-row>
    <br>
    <br>
    <br>
    <el-row>
      <el-col>
        <div class="grid-content bg-purple">
          <i class="el-icon-s-promotion"> </i> 应收租约保理
          <hr>
          <div class="about">
            <el-table
              :data="tableData2"
            >
              <el-table-column
                prop="jrProductName"
                label="产品名称"
              >
              </el-table-column>
              <el-table-column
                prop="companyName"
                label="资方"
              >
              </el-table-column>
              <el-table-column
                prop="bankName"
                label="银行名称"
              >
              </el-table-column>
              <el-table-column
                prop="bankCardNumber"
                label="账户信息"
              >
              </el-table-column>
              <el-table-column
                prop="repaymentType"
                label="还款方式"
              >
                <template scope="scope">
                  <div v-if="scope.row.repaymentType==1">按月还款</div>
                  <div v-if="scope.row.repaymentType==2">按季还款</div>
                  <div v-if="scope.row.repaymentType==3">按租约周期支付</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="creditLine"
                label="授信额度"
              >
              </el-table-column>
              <el-table-column
                prop="delFlg"
                label="状态"
              >
                <template scope="scope">
                  <div v-if="scope.row.delFlg==0" style="color: green">正常</div>
                  <div v-if="scope.row.delFlg==1" style="color: red">已作废</div>
                </template>
              </el-table-column>
              <el-table-column
                fixed="right"
                label="操作"
                width="200">
                <template scope="scope">
                  <div v-if="scope.row.delFlg==0">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button
                      type="text"
                      size="small"
                      @click="handleEdit(scope.row)">编辑
                    </el-button>
                    <el-button
                      size="small"
                      type="text"

                      @click="handleDelFlg(scope.row)">作废
                    </el-button>
                  </div>
                  <div v-if="scope.row.delFlg==1">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button
                      type="text"
                      size="small"
                      @click="handleEdit(scope.row)" disabled>编辑
                    </el-button>
                    <el-button
                      size="small"
                      type="text"
                      @click="handleDelete(scope.row)">删除
                    </el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-dialog title="收货地址" :visible.sync="dialogTableVisible">
      <el-form ref="form" :model="forms" label-width="80px">
        <el-form-item label="产品名称">
          <el-input v-model="forms.jrProductName"></el-input>
        </el-form-item>
        <el-form-item label="资方">
          <el-input v-model="forms.companyName"></el-input>
        </el-form-item>
        <el-form-item label="银行名称">
          <el-input v-model="forms.bankName"></el-input>
        </el-form-item>
        <el-form-item label="账户信息">
          <el-input v-model="forms.bankCardNumber"></el-input>
        </el-form-item>
        <el-form-item label="还款方式">
          <el-radio-group v-model="forms.repaymentType">
            <el-radio :label="1">按月还款</el-radio>
            <el-radio :label="2">按月还款</el-radio>
            <el-radio :label="3">按季度还款</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="授信额度">
          <el-input v-model="forms.creditLine"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateProduct">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--  查看    -->
    <el-dialog title="收货地址" :visible.sync="dialogTableVisible2">
      <el-form ref="form" :model="forms" label-width="80px">
        <el-form-item label="产品名称">
          {{ forms.jrProductName }}
        </el-form-item>
        <el-form-item label="资方">
          {{ forms.companyName }}
        </el-form-item>
        <el-form-item label="银行名称">
          {{ forms.bankName }}
        </el-form-item>
        <el-form-item label="账户信息">
          {{ forms.bankCardNumber }}
        </el-form-item>
        <el-form-item label="还款方式">
          {{ forms.repaymentType == 1 ? "按月还款" : "" }}
          {{ forms.repaymentType == 2 ? "按季还款" : "" }}
          {{ forms.repaymentType == 3 ? "按租约周期支付" : "" }}
        </el-form-item>
        <el-form-item label="授信额度">
          {{ forms.creditLine }}
        </el-form-item>
      </el-form>
    </el-dialog>
  </el-main>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      tableData: [],
      tableData1: [],
      tableData2: [],
      forms: {
        jrProductName: '',
        companyName: '',
        bankName: '',
        bankCardNumber: '',
        repaymentType: '',
        creditLine: '',
      },
      dialogTableVisible: false,
      dialogTableVisible2: false

    }
  },
  methods: {
    productOne() {
      axios({
        method: 'post',
        url: 'http://localhost:8200/jrfwcwgl/product/productTypeOne',
      }).then((res) => {
        if (res) {
          this.tableData = res.data.obj;
        }
      })
    },
    productTwo() {
      axios({
        method: 'post',
        url: 'http://localhost:8200/jrfwcwgl/product/productTypeTwo',
      }).then((res) => {
        if (res) {
          this.tableData1 = res.data.obj;
        }
      })
    },
    productThree() {
      axios({
        method: 'post',
        url: 'http://localhost:8200/jrfwcwgl/product/productTypeThree',
      }).then((res) => {
        if (res) {
          this.tableData2 = res.data.obj;
        }
      })
    },
    handleEdit(row) {
      this.dialogTableVisible = true;
      this.forms = row;
      console.log(this.forms.repaymentType)
    },
    handleClick(row) {
      console.log(row);
      this.dialogTableVisible2 = true;
      this.forms = row;
    },
    handleDelete(row) {
      if (!confirm("确定删除吗？")){
        return;
      }
      axios.post("http://localhost:8200/jrfwcwgl/product/deleteProduct?id="+row.id).then(res=>{
        if (res.status==200){
          this.$message.success("删除成功");
          this.productOne();
          this.productTwo();
          this.productThree();
        }else{
          this.$message.error("删除失败");
        }
        this.dialogTableVisible=false;
      })
    },
    updateProduct() {
      console.log(this.forms);
      axios.post("http://localhost:8200/jrfwcwgl/product/updateProduct",this.forms).then(res=>{
        if (res.status==200){
          this.$message.success("修改成功");
          this.productOne();
          this.productTwo();
          this.productThree();
        }else{
          this.$message.error("修改失败");
        }
        this.dialogTableVisible=false;
      })
    },
    handleDelFlg(row){
      if (!confirm("确定要作废吗？")){
        return;
      }
      axios.post("http://localhost:8200/jrfwcwgl/product/updateDelFlagProduct?id="+row.id).then(res=>{
        if (res.status==200){
          this.$message.success("作废成功");
          this.productOne();
          this.productTwo();
          this.productThree();
        }else{
          this.$message.error("作废失败");
        }
      })
    }
  },
  created() {
    this.productOne();
    this.productTwo();
    this.productThree();
  }
}
</script>
